package ch4;

import java.util.Arrays;

// 公司有公司名称，注册地址，电话，经营范围等属性，公司有很多员工（暂用数组表示），
// 员工有姓名，年龄，性别，职务，薪水等属性，公司有招聘员工，有输出员工信息，以及辞退员工，和统计公司人数的方法
//用oo的思想模拟，相关类用构造方法初始化。
public class Company {
    String name = "拖拉机厂", address = "地球一个角落", //公司名称，注册地址，电话，经营范围
            telephone = "0000-66666666", businessScope = "研发以及生产超级拖拉机，销售并进行售后服务！";
    Staff[] s = new Staff[1000];
    int count = 0;

    public void show() {
        System.out.println("公司名称：" + name + "\n注册地址：" + address + "\n电话："
                + telephone + "\n经营范围：" + businessScope);
    }

    //加人
    public boolean add(Staff y) {
        if (count >= s.length) {
            return false;
        }
        s[count++] = y;
        return true;
    }

    //查看员工信息
    public void showStaff() {
        if (count == 0)
            return;
        System.out.println("员工信息：");
        System.out.println("序号  " + "姓名  " + "性别  " + "年龄  " + "职务   " + "薪资");
        for (int i = 0; i < count; i++) {
            System.out.println((i + 1) + "  " + s[i].name + "  " + s[i].sex + "  " + s[i].age
                    + "  " + s[i].position + "   " + s[i].salary);
        }
    }

    //删除员工信息
    public boolean delete(String oldName) {
        if (count == 0)
            return false;
        for (int i = 0; i < count; i++) {
            if (oldName.equals(s[i].name)) {
                for (int j = i; j < count - 1; j++) {
                    s[j] = s[j + 1];
                    if (s[j + 1] == null)
                        break;
                }
                s[count - 1] = null;
                count--;
                return true;
            }
        }
        return false;
    }

    //统计员工数量
    public int nuber() {
        return count;
    }

    //最高工资
    public void findTopSalary() {
        //     public Staff findTopSalary() {
        if (count == 0)
            return;
        double max = s[0].salary;
        int j = 0;
        for (int i = 1; i < count; i++) {
            if (max < s[i].salary) {
                max = s[i].salary;
                j = i;
            }
        }
        System.out.println("公司最高工资是" + "\n姓名：" + s[j].name + "\n年龄：" + s[j].age +
                "\n性别：" + s[j].sex + "\n职务：" + s[j].position + "\n薪水：" + s[j].salary);
        //           return Staff s;
    }

    //工资排序
    public void sortBySalDesc() {
        Staff n;
        for (int i = 0; i < count; i++) {
            for (int j = i; j < count ; j++) {
                if (s[i].salary < s[j].salary) {
                    n = s[j];
                    s[j] = s[i];
                    s[i] = n;
                }
            }
        }
    }

    //平均工资
    public double avgSalary() {
        double total = 0;
        for (int i = 0; i < count; i++) {
            total += s[i].salary;
        }
        return total / count;
    }

    //涨工资
    public void salaryiIncrease() {
        for (int i = 0; i < count; i++) {
            if (s[i].salary < 5000) {
                s[i].salary += 500;
                continue;
            }
            s[i].salary += 100;
        }
    }
}